home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 401-425 / disk_405 / gifmachine / sources / extensions.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  2KB  |  95 lines

  1. /* Copyright 1990 by Christopher A. Wichura.
  2.    See file GIFMachine.doc for full description of rights.
  3. */
  4.  
  5. #include "GIFMachine.h"
  6.  
  7. struct MinList CommentList;
  8. static UBYTE buf[256];
  9.  
  10. BOOL DoExtension(BPTR fh)
  11. {
  12.     register LONG size;
  13.     register LONG cmdcode;
  14.     register char *Comment;
  15.     register char *OldComment;
  16.     register int CommentLength;
  17.     register int OldCommentLength;
  18.     register struct CommentNode *cn;
  19.  
  20.     if ((cmdcode = FGetC(fh)) == -1) {
  21.         PutStr("...I/O error reading extension block function code\n");
  22.         return TRUE;
  23.     }
  24.  
  25.     switch(cmdcode) {
  26.         case GIF_COMMENT_EXT:
  27.             PutStr("...Comment extension encountered.  Contents will be stored in an ANNO chunk.\n");
  28.  
  29.             if (!(cn = (struct CommentNode *)MyAlloc(sizeof(struct CommentNode)))) {
  30.                 PutStr("......Out of memory allocating comment block.\n");
  31.                 return TRUE;
  32.             }
  33.  
  34.             Comment = NULL;
  35.             CommentLength = 0;
  36.  
  37.             for (;;) {
  38.                 if ((size = FGetC(fh)) == -1) {
  39.                     PutStr("......I/O Error reading comment block.\n");
  40.                     return TRUE;
  41.                 }
  42.  
  43.                 if (size) {
  44.                     if (FRead(fh, buf, 1, size) != size) {
  45.                         PutStr("......I/O Error reading comment block.\n");
  46.                         return TRUE;
  47.                     }
  48.  
  49.                     OldComment = Comment;
  50.                     OldCommentLength = CommentLength;
  51.                     CommentLength += size;
  52.  
  53.                     if (!(Comment = MyAlloc(CommentLength))) {
  54.                         PutStr("......Out of memory allocating comment block.\n");
  55.                         return TRUE;
  56.                     }
  57.  
  58.                     if (OldCommentLength) {
  59.                         CopyMem(OldComment, Comment, OldCommentLength);
  60.                         MyFree(OldComment);
  61.                     }
  62.  
  63.                     CopyMem(buf, &Comment[OldCommentLength], size);
  64.                 } else {    /* end of comment so store it */
  65.                     cn->cn_Comment = Comment;
  66.                     cn->cn_CommentLength = CommentLength;
  67.                     AddTail((struct List *)&CommentList, (struct Node *)cn);
  68.                     return FALSE;
  69.                 }
  70.             }
  71.             break;
  72.  
  73.         default:
  74.             MyPrintf("...Extension block function code #%ld not know, skipping.\n",
  75.              cmdcode);
  76.  
  77.             /* we must skip over any data for the extension block */
  78.             for (;;) {
  79.                 if ((size = FGetC(fh)) == -1) {
  80.                     PutStr("...I/O Error skipping unknown extension block.\n");
  81.                     return TRUE;
  82.                 }
  83.  
  84.                 if (size == 0)
  85.                     return FALSE;
  86.  
  87.                 if (FRead(fh, buf, 1, size) != size) {
  88.                     PutStr("...I/O Error skipping unknown extension block.\n");
  89.                     return TRUE;
  90.                 }
  91.             }
  92.             break;
  93.     }
  94. }
  95.